package com.shop.common;

import java.lang.reflect.Method;

public class ObjectUtil {


    public static void annotationToObject(Object annotation, Object object) {
        if (annotation != null&& object!=null) {
            Class<?> annotationClass = annotation.getClass();
            Class<?> objectClass = object.getClass();
            for (Method m : objectClass.getMethods()) {
                if (StringUtil.startsWith(m.getName(), "set")) {
                    try {
                        String s = StringUtil.substring(m.getName(), 3);
                        Object obj = annotationClass.getMethod("get" + s).invoke(annotation);
                        if (obj != null) {
                            m.invoke(object, obj);
                        }
                    } catch (Exception e) {
                    }
                }
            }
        }
    }


}
